var fs = require("fs");
var path = require("path");


var mslibrary = require('ms-common-library');

var qr_image = require("qr-image");

module.exports = function (UC, source, config, ArFor, cache, package) {

    var router = function (req, res, next) {

        var params = req.params;
        if (params.type == "linkid") {
            new source({
                "SQL": "SELECT * FROM qrcodelist as db where db.linkid='{linkid}';",
                "type": "row"
            }, {
                linkid: params.value 
            }, function (db) {
                db=db||{value:"error",_expansion:'{}'};
                var temp_qrcode = qr_image.image(db.value,JSON.parse(db._expansion));
                res.type("png");
                temp_qrcode.pipe(res);
            })
        } else {
            var temp_qrcode = qr_image.image(params.value);
            res.type("png");
            temp_qrcode.pipe(res);
        }
    }
    return router;

}